import 'dart:convert';

import 'package:changxindianzishangwu/http/base/ec_base_request.dart';
import 'package:changxindianzishangwu/http/base/http_urls.dart';
import 'package:changxindianzishangwu/http/request/check_version_apk.dart';
import 'package:changxindianzishangwu/http/request/upLoadFile_requset.dart';
import 'package:changxindianzishangwu/http/zd_net.dart';
import 'package:changxindianzishangwu/model/dynamic_media_model.dart';
import 'package:changxindianzishangwu/util/update/update_info_model.dart';
import 'package:dio/dio.dart';

class UpLoadFileDao {
  static addFile(FormData formData) async {
    EcBaseRequest request = UpLoadFileRequest();
    request.addData(formData);

    var result = await ZdNet.getInstance().send(request);
    var data = jsonDecode(result.toString());
    DynamicMediaModel model = DynamicMediaModel.fromJson(data);

    if (model.resultCode == 1) {
      if (model.data.others != null) {
        model.data.images.addAll(model.data.others);
      }
    }
    // print("=============${model.data}");
    return model;
  }
  static checkVersion() async {
    EcBaseRequest request = CheckVersionApkRequest();
    var result = await ZdNet.getInstance().send(request);
    return UpdateInfoModel.fromJson(result);
  }

  ///下载文件
  static Future downloadFile(String urlPath, String savePath,
      {ProgressCallback onReceiveProgress}) async {

    Response response = await Dio().download(urlPath, savePath,
        onReceiveProgress: onReceiveProgress);
    return response;
  }

}
